import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
    public static void main(String[] args) {
    	ServerSocket server = null;
    	try {
    		server = new ServerSocket(5555);
    		while(true){
    			final Socket socket = server.accept();
    			new Thread(){
    				public void run() {
    					try {
    						System.out.println("Sever 连接来了");
        	    			InputStream reader = socket.getInputStream();
        	    			while(true){
        	    				int len = 0;
            	    			while((len = reader.available()) <= 0){
            	    				len = reader.available();
            	    			}
            	    			byte[] data = new byte[len];
            	    			reader.read(data);
            	    			
            	    			System.out.println(new String(data));
            	    			
        	    			}
						} catch (Exception e) {}
    				};
    			}.start();
    			
    		}
		} catch (Exception e) {
			try {
				if(server != null)
					server.close();
			} catch (Exception e2) {}
		}
    }
}